package ManageGameHServer.code;

import ManageGameHServer.bean.member.*;
import ManageGameHServer.bean.member.log.*;
import ManageGameHServer.classFile.DBConnectO;
import ManageGameHServer.classFile.Log;
import ManageGameHServer.classFile.LogDBConnectO;
import org.json.JSONArray;
import org.json.JSONObject;


import java.sql.*;
import java.util.*;
import java.util.Date;

/**
 * 解析监听到的日志并保存
 * @author lijie1
 */
public class ExplainMessage {
    public void explainMsgForSwitch(JSONArray msg){
        int msgType = 0;
        try {
            msgType = msg.getInt(0);//消息的类型（1用户信息2新用户进入游戏大厅3单服务上线统计4用户上线5用户下线67用户进入游戏8用户退出游戏）
            String userId = "";//用户的id
            long loginTime = 0;//用户登录系统时间
            long logoutTime = 0;//用户退出系统时间
            String serverNo = "";//服务器编号
            String connects = "";//上下连接段
            String gameType = "";//游戏类型
            long multiple = 0;//游戏倍数
            long createTime = 0;//日志时间
            String orderNo="";//订单号
            try {
                JSONArray contentMsg = msg.getJSONArray(1);
                try {
                    switch(msgType){
                        case 1:
                            if (contentMsg.length() == 4) {
                                if ("null".equals(contentMsg.get(0).toString())) {
                                    System.out.println("收到错误消息:消息内容：" + contentMsg + "消息编号：" + msgType + "用户id为空");
                                    break;
                                }
                                userId = contentMsg.get(0).toString();//用户id
                                loginTime = Long.parseLong(contentMsg.get(1).equals(null) ? "0" : contentMsg.get(1) + "000");//登录时间
                                logoutTime = Long.parseLong(contentMsg.get(2).equals(null) ? "0" : contentMsg.get(2) + "000");//登出时间
                                String userIp = contentMsg.get(3).toString();//登录ip
                                //会员日志信息
                                MemberInfoLog entity = new MemberInfoLog();//用户信息实体
                                entity.setIp(userIp);
                                entity.setUserId(userId);
                                entity.setOnlineTime(new Date(loginTime));
                                entity.setOfflineTime(new Date(logoutTime));
                                saveMemberInfoLog(entity);//存储会员消息日志
                                MemberOfflineLog memberOfflineLogs = new MemberOfflineLog();
                                memberOfflineLogs.setUserId(userId);
                                deleteMemberOnline(memberOfflineLogs);//存储会员下线
                            }else {
                                System.out.println("收到错误消息:消息内容：" + contentMsg + "消息编号：" + msgType+"消息长度："+contentMsg.length());
                                break;
                            }

                            break;
                        case 2:
                            if (contentMsg.length() == 10) {

                                if ("null".equals(contentMsg.get(0).toString())) {
                                    System.out.println("收到错误消息:消息内容：" + contentMsg + "消息编号：" + msgType + "用户id为空");
                                    break;
                                }
                                userId = contentMsg.getString(0);
                                String userName = contentMsg.getString(1);
                                createTime = Long.parseLong(contentMsg.get(2) + "000");//注册时间
                                String loginIp = contentMsg.getString(3);//注册ip
                                Double balance = contentMsg.getDouble(4);//初期余额
                                int userType = contentMsg.getInt(5);//账号类型 100 手机号 200 邮箱 300 自定义
                                String businessId = contentMsg.getString(6);//商家号
                                String AppId = contentMsg.getString(7);//注册终端
                                String nickName = contentMsg.getString(8);//昵称
                                String fundsType = contentMsg.getString(9);//资金类型
                                AppId = AppId.toLowerCase();
                                //用户注册日志
                                MemberRegisterLog memberRegisterLog = new MemberRegisterLog();
                                memberRegisterLog.setUserId(userId);
                                memberRegisterLog.setUserName(userName);
                                memberRegisterLog.setCreateTime(new Date(createTime));
                                memberRegisterLog.setIp(loginIp);
                                memberRegisterLog.setBalance(balance);
                                memberRegisterLog.setUserType(userType);
                                memberRegisterLog.setBusinessId(businessId);
                                memberRegisterLog.setAppId(AppId);
                                memberRegisterLog.setNickName(nickName);
                                memberRegisterLog.setFundsType(fundsType);
                                saveMemberRegisterLog(memberRegisterLog);//存储新增会员日志

                                //注册会员基本信息
                                MemberInfo memberInfo = new MemberInfo();
                                memberInfo.setAccount(userName);//账号
                                memberInfo.setRegister_time(new Date(createTime));
                                memberInfo.setCur_amount(balance);
                                memberInfo.setAccount_type(userType);
                                if(userType==100){
                                    memberInfo.setPhoneNumber(userName);
                                }
                                memberInfo.setAccountName(userId);
                                memberInfo.setRegister_channel(AppId);
                                memberInfo.setNickName(nickName);
                                memberInfo.setFoundTypeId(fundsType);
                                saveMemberInfo(memberInfo);
                            }else {
                                System.out.println("收到错误消息:消息内容：" + contentMsg + "消息编号：" + msgType+"消息长度："+contentMsg.length());
                                break;
                            }

                            break;
                        case 3:
                            if (contentMsg.length() == 4) {
                                serverNo = contentMsg.getString(0);
                                long dateTime = Long.parseLong(contentMsg.get(1) + "000");
                                long links = contentMsg.getLong(2);
                                JSONArray userIds = contentMsg.getJSONArray(3);
                                ServerLog serverLog = new ServerLog();
                                serverLog.setServerNo(serverNo);
                                serverLog.setLogTime(new Date(dateTime));
                                serverLog.setNumber(links);
                                serverLog.setUserIds(userIds.toString());
                                saveServerLog(serverLog);//服务器日志
                                if(userIds.length()>0){
                                    for (int i = 0; i < userIds.length(); i++) {
                                        JSONArray userIdJSONArray = userIds.getJSONArray(i);
                                        MemberOnLine memberOnLine = new MemberOnLine();
                                        memberOnLine.setUserId(userIdJSONArray.getString(0));
                                        memberOnLine.setOnLineIp(userIdJSONArray.getString(1));
                                        saveMemberOnline(memberOnLine);
                                    }
                                }else {
                                    deleteMemberOnlineAll();
                                }
                            }else {
                                System.out.println("收到错误消息:消息内容：" + contentMsg + "消息编号：" + msgType+"消息长度："+contentMsg.length());
                                break;
                            }

                            break;
                        case 4:
                            if (contentMsg.length() == 7) {
                                if ("null".equals(contentMsg.get(0).toString())) {
                                    System.out.println("收到错误消息:消息内容：" + contentMsg + "消息编号：" + msgType + "用户id为空");
                                    break;
                                }
                                userId = contentMsg.getString(0);//用户id
                                serverNo = contentMsg.getString(1);
                                long onLineTime = Long.parseLong(contentMsg.get(2) + "000");//会员上线时间
                                connects = contentMsg.getString(3);//连接段
                                String onLineIp = contentMsg.getString(4);//上线ip
                                String userName = contentMsg.getString(5);//账号名称
                                String nickName = contentMsg.getString(6);//昵称
                                //存储会员上线日志
                                MemberOnlineLog memberOnLineLog = new MemberOnlineLog();
                                memberOnLineLog.setUserId(userId);
                                memberOnLineLog.setServerNo(serverNo);
                                memberOnLineLog.setOnLineTime(new Date(onLineTime));
                                memberOnLineLog.setKey(connects);
                                memberOnLineLog.setOnLineIp(onLineIp);
                                memberOnLineLog.setNickName(nickName);
                                saveMemberOnlineLog(memberOnLineLog);//存储会员上线日志
                                saveAndUpdateMemberOnLine(memberOnLineLog);//存储会员上线

                                //注册会员基本信息
                                MemberInfo memberInfo1 = new MemberInfo();
                                memberInfo1.setAccount(userName);
                                memberInfo1.setAccountName(userId);//账号
                                memberInfo1.setRegister_time(new Date(onLineTime));
                                memberInfo1.setCur_amount(0);
                                memberInfo1.setLoginTime(new Date(onLineTime));
                                updateMemberInfoByLoginTime(memberInfo1);
                                int i = queryMemberInfoCount(memberInfo1);
                                if (i==0) {
                                    saveMemberInfo(memberInfo1);
                                }
                                memberInfo1.setNickName(nickName);
                                updateMemberInfoByRegisterTime(memberInfo1,true);
                                updateMemberInfoByNickName(memberInfo1);
                            }else {
                                System.out.println("收到错误消息:消息内容：" + contentMsg + "消息编号：" + msgType+"消息长度："+contentMsg.length());
                                break;
                            }

                            break;
                        case 5:
                            if (contentMsg.length() == 6) {
                                if ("null".equals(contentMsg.get(0).toString())) {
                                    System.out.println("收到错误消息:消息内容：" + contentMsg + "消息编号：" + msgType + "用户id为空");
                                    break;
                                }
                                serverNo = contentMsg.getString(1);//服务器编号
                                userId = contentMsg.getString(0);//用户id
                                long offLineTime = Long.parseLong(contentMsg.get(2) + "000");//下线时间
                                connects = contentMsg.getString(3);//连接段
                                String offLineIp = contentMsg.getString(4);//下线ip
                                double balance = contentMsg.getDouble(5);//下线时余额
                                //用户下线日志
                                MemberOfflineLog memberOfflineLog = new MemberOfflineLog();
                                memberOfflineLog.setUserId(userId);
                                memberOfflineLog.setServerNo(serverNo);
                                memberOfflineLog.setOffLineTime(new Date(offLineTime));
                                memberOfflineLog.setKey(connects);
                                memberOfflineLog.setOffLineIp(offLineIp);
                                memberOfflineLog.setBalance(balance);
                                saveMemberOfflineLog(memberOfflineLog);//存储会员下线日志

                                deleteMemberOnline(memberOfflineLog);//存储会员下线
                                //用户资金变化
                                MemberInfo memberInfo3 = new MemberInfo();
                                memberInfo3.setAccount(userId);//账号
                                memberInfo3.setCur_amount(balance);//余额
                                updateMemberInfo(memberInfo3,false);
                                updateMemberInfoByRegisterTime(memberInfo3,false);
                            }else {
                                System.out.println("收到错误消息:消息内容：" + contentMsg + "消息编号：" + msgType+"消息长度："+contentMsg.length());
                                break;
                            }

                            break;
                        case 6:

                            break;
                        case 7:
                            if (contentMsg.length() == 7) {
                                if ("null".equals(contentMsg.get(0).toString())){
                                    System.out.println("收到错误消息:消息内容：" + contentMsg + "消息编号：" + msgType + "用户id为空");
                                    break;
                                }
                                userId = contentMsg.getString(0);//用户id
                                long goLineTime = Long.parseLong(contentMsg.get(2) + "000");//上线时间
                                serverNo = contentMsg.getString(1);//服务器编号

                                gameType = contentMsg.getString(3);//游戏类型
                                multiple = contentMsg.getLong(4);//游戏倍数
                                connects = contentMsg.getString(5);//连接段
                                String goLineIp = contentMsg.getString(6);//进入游戏ip
                                //用户进行游戏日志
                                MemberEnterGameLog memberEnterGameLog = new MemberEnterGameLog();
                                memberEnterGameLog.setUserId(userId);
                                memberEnterGameLog.setServerNo(serverNo);
                                memberEnterGameLog.setEnterGameTime(new Date(goLineTime));
                                memberEnterGameLog.setGameType(gameType);
                                memberEnterGameLog.setMultiple(multiple);
                                memberEnterGameLog.setKey(connects);
                                memberEnterGameLog.setEnterGameIp(goLineIp);
                                saveMemberEnterGameLog(memberEnterGameLog);
                                int i = queryMemberGameInfo(memberEnterGameLog);
                                if(i==0){
                                    saveMemberGame(memberEnterGameLog);
                                }

                            }else {
                                System.out.println("收到错误消息:消息内容：" + contentMsg + "消息编号：" + msgType+"消息长度："+contentMsg.length());
                                break;
                            }

                            break;
                        case 8:
                            if (contentMsg.length() == 8) {
                                if ("null".equals(contentMsg.get(0).toString())) {
                                    System.out.println("收到错误消息:消息内容：" + contentMsg + "消息编号：" + msgType + "用户id为空");
                                    break;
                                }
                                userId = contentMsg.getString(0);//用户id
                                serverNo = contentMsg.getString(1);//服务器编号
                                long outLineTime = Long.parseLong(contentMsg.get(2) + "000");//下线时间
                                connects = contentMsg.getString(3);//连接段
                                gameType = contentMsg.getString(4);//游戏类型
                                multiple = contentMsg.getLong(5);//游戏倍数
                                String balanceChange = contentMsg.getString(6);//游戏余额变化量
                                String quitGameIp = contentMsg.getString(7);//进入游戏ip
                                if (balanceChange.indexOf("_") < 0) {
                                    System.out.println("收到错误消息:消息内容：" + contentMsg + "消息编号：" + msgType);
                                    break;
                                }
                                //用户游戏退出日志
                                MemberQuitGameLog memberQuitGameLog = new MemberQuitGameLog();
                                memberQuitGameLog.setUserId(userId);
                                memberQuitGameLog.setServerNo(serverNo);
                                memberQuitGameLog.setQuitGameTime(new Date(outLineTime));
                                memberQuitGameLog.setKey(connects);
                                memberQuitGameLog.setGameType(gameType);
                                memberQuitGameLog.setMultiple(multiple);
                                memberQuitGameLog.setBalanceChange(balanceChange);
                                memberQuitGameLog.setQuitGameIp(quitGameIp);
                                saveMemberQuitGameLog(memberQuitGameLog);
                                deleteMemberGame(memberQuitGameLog);
                                //用户资金变化
                                String[] balances = balanceChange.split("_");
                                Double balanceOld = "".equals(balances[0]) ? 0.0 : Double.parseDouble(balances[0]);
                                Double balanceNew = "".equals(balances[1]) ? 0.0 : Double.parseDouble(balances[1]);
                                MemberInfo memberInfo2 = new MemberInfo();
                                memberInfo2.setAccountName(userId);//账号
                                memberInfo2.setCur_amount(balanceNew - balanceOld);//变化余额
                                updateMemberInfo(memberInfo2,true);
                            }else {
                                System.out.println("收到错误消息:消息内容：" + contentMsg + "消息编号：" + msgType+"消息长度："+contentMsg.length());
                                break;
                            }

                            break;
                        case 9:
                            if (contentMsg.length() == 5) {
                                if ("null".equals(contentMsg.get(0).toString())) {
                                    System.out.println("收到错误消息:消息内容：" + contentMsg + "消息编号：" + msgType + "用户id为空");
                                    break;
                                }
                                userId = contentMsg.getString(0);//用户id
                                orderNo = contentMsg.getString(1);//订单号
                                long fundsZ = contentMsg.getLong(2);//增加金额
                                createTime = Long.parseLong(contentMsg.get(3) + "000");//时间
                                String ip = contentMsg.getString(4);//ip
                                MemberRechargeLog memberRechargeLog = new MemberRechargeLog();
                                memberRechargeLog.setUserId(userId);
                                memberRechargeLog.setOrderNo(orderNo);
                                memberRechargeLog.setValue(fundsZ);
                                memberRechargeLog.setCreateDate(new Date(createTime));
                                memberRechargeLog.setCreateTime(contentMsg.getLong(3));
                                memberRechargeLog.setIp(ip);
                                saveMemberRechargeLog(memberRechargeLog);
                            }else {
                                System.out.println("收到错误消息:消息内容：" + contentMsg + "消息编号：" + msgType+"消息长度："+contentMsg.length());
                                break;
                            }

                            break;
                        case 10:
                            if (contentMsg.length() == 5) {
                                if ("null".equals(contentMsg.get(0).toString())) {
                                    System.out.println("收到错误消息:消息内容：" + contentMsg + "消息编号：" + msgType + "用户id为空");
                                    break;
                                }
                                userId = contentMsg.getString(0);//用户id
                                orderNo = contentMsg.getString(1);//订单号
                                long fundsD = contentMsg.getLong(2);//冻结金额
                                createTime = Long.parseLong(contentMsg.get(3) + "000");//时间
                                String ip = contentMsg.getString(4);//ip
                                MemberWithdrawalLog memberWithdrawalLog = new MemberWithdrawalLog();
                                memberWithdrawalLog.setUserId(userId);
                                memberWithdrawalLog.setOrderNo(orderNo);
                                memberWithdrawalLog.setValue(fundsD);
                                memberWithdrawalLog.setCreateDate(new Date(createTime));
                                memberWithdrawalLog.setCreateTime(contentMsg.getLong(3));
                                memberWithdrawalLog.setIp(ip);
                                saveMemberWithdrawalLog(memberWithdrawalLog);
                            }else {
                                System.out.println("收到错误消息:消息内容：" + contentMsg + "消息编号：" + msgType+"消息长度："+contentMsg.length());
                                break;
                            }

                            break;
                        case 12:
                            if(contentMsg.length() == 3){
                                if ("null".equals(contentMsg.get(0).toString())) {
                                    System.out.println("收到错误消息:消息内容：" + contentMsg + "消息编号：" + msgType);
                                    break;
                                }
                                userId = contentMsg.getString(0);//用户id
                                int operationStatus = contentMsg.getInt(1);//订单号
                                createTime = Long.parseLong(contentMsg.get(2) + "000");//时间
                                MemberShowTradeFlowLog info = new MemberShowTradeFlowLog();
                                info.setUserId(userId);
                                info.setOperationStatus(operationStatus);
                                info.setCreateTime(contentMsg.getLong(2));
                                info.setCreateDate(new Date(createTime));
                                saveMemberShowTradeFlowLog(info);
                            }else {
                                System.out.println("收到错误消息:消息内容：" + contentMsg + "消息编号：" + msgType+"消息长度："+contentMsg.length());
                                break;
                            }

                            break;
                        case 13:
                            if(contentMsg.length() == 3){
                                if ("null".equals(contentMsg.get(0).toString())) {
                                    System.out.println("收到错误消息:消息内容：" + contentMsg + "消息编号：" + msgType);
                                    break;
                                }
                                userId = contentMsg.getString(0);//用户id
                                createTime = Long.parseLong(contentMsg.get(2) + "000");//时间
                                JSONArray data01 = contentMsg.getJSONArray(1);
                                MemberDrawingAccountLog memberDrawingAccountLog = new MemberDrawingAccountLog();
                                memberDrawingAccountLog.setUserId(userId);
                                memberDrawingAccountLog.setContent(data01.toString());
                                memberDrawingAccountLog.setCreateDate(new Date(createTime));
                                memberDrawingAccountLog.setCreateTime(contentMsg.getLong(2));
                                saveMemberDrawingAccountLog(memberDrawingAccountLog);
                                List<Map<String,String>> list = queryMemberInfo(userId);
                                String userName = "";
                                if(list.size()>0){
                                    userName = list.get(0).get("account");
                                }
                                for (int i = 0; i < data01.length(); i++) {
                                    JSONArray data02 = data01.getJSONArray(i);
                                    MemberBankAccount memberBankAccount = new MemberBankAccount();
                                    memberBankAccount.setGameAccount(userName);
                                    memberBankAccount.setBankAccount(data02.getString(0));
                                    memberBankAccount.setBankAccountName(data02.getString(1));
                                    memberBankAccount.setDrawingType(Integer.parseInt(data02.getString(2)));
                                    saveMemberBankAccount(memberBankAccount);
                                }
                            }else {
                                System.out.println("收到错误消息:消息内容：" + contentMsg + "消息编号：" + msgType+"消息长度："+contentMsg.length());
                                break;
                            }

                            break;
                        case 101:
                            if (contentMsg.length() == 6) {
                                if ("null".equals(contentMsg.get(0).toString())) {
                                    System.out.println("收到错误消息:消息内容：" + contentMsg + "消息编号：" + msgType);
                                    break;
                                }
                                userId = contentMsg.getString(0);//用户id
                                gameType = contentMsg.getString(1);//游戏类型
                                multiple = contentMsg.getLong(2);//游戏倍数
                                createTime = contentMsg.getLong(3);//下注时间
                                String balanceChange = contentMsg.getString(4);//游戏余额变化量
                                String orderId = contentMsg.getString(5);//订单单号
                                if (balanceChange.indexOf("_") < 0) {
                                    System.out.println("收到错误消息:消息内容：" + contentMsg + "消息编号：" + msgType);
                                    break;
                                }
                                //会员的资金流水日志
                                MemberFundFlowLog memberFundFlowLog = new MemberFundFlowLog();
                                memberFundFlowLog.setUserId(userId);
                                memberFundFlowLog.setGameType(gameType);
                                memberFundFlowLog.setMultiple(multiple);
                                memberFundFlowLog.setGameTime(new Date(createTime));
                                memberFundFlowLog.setBalanceChange(balanceChange);
                                memberFundFlowLog.setOrderId(orderId);
                                saveMemberFundFlowLog(memberFundFlowLog);
                                //会员资金流水
                                MemberRunWater memberRunWater = new MemberRunWater();
                                memberRunWater.setGameAccount(userId);
                                memberRunWater.setBettingTime(new Date(createTime));
                                memberRunWater.setGameType(1);
                                memberRunWater.setGameName(gameType);
                                //用户资金变化
                                String[] balances1 = balanceChange.split("_");
                                Double fundOld = "".equals(balances1[0]) ? 0.0 : Double.parseDouble(balances1[0]);
                                Double fundNew = "".equals(balances1[1]) ? 0.0 : Double.parseDouble(balances1[1]);
                                Double effectBet = "".equals(balances1[2]) ? 0.0 : Double.parseDouble(balances1[2]);
                                Double effectBet1 = effectBet;
                                double betResult = fundNew - fundOld;
                                double betAmount = betResult;
                                if (betAmount > 0) {
                                    betAmount = betAmount / multiple;
                                } else {
                                    betAmount = betAmount * -1 / multiple;
                                    effectBet1 = -effectBet1;
                                }
                                memberRunWater.setBetAmount(betAmount);
                                memberRunWater.setBetResult(betResult);
//                            saveMemberRunWater(memberRunWater);

                                MemberInfo memberInfo4 = new MemberInfo();
                                memberInfo4.setAccountName(userId);//账号
                                //memberInfo4.setCur_amount(betResult);//变化余额
                                memberInfo4.setEffectBet(effectBet);
                                memberInfo4.setEffectBetBalance(effectBet1);
                                updateMemberInfoByEffectBet(memberInfo4);
                                MemberFundsFlow memberFundsFlow = new MemberFundsFlow();
                                memberFundsFlow.setUserId(userId);
                                memberFundsFlow.setFundsflow(effectBet);
                                saveMemberFundsFlow(memberFundsFlow);
                            }else {
                                System.out.println("收到错误消息:消息内容：" + contentMsg + "消息编号：" + msgType+"消息长度："+contentMsg.length());
                                break;
                            }

                            break;
                        case 102:
                            if (contentMsg.length() == 5) {
                                gameType = contentMsg.getString(0);//游戏类型
                                multiple = contentMsg.getLong(1);//游戏倍数
                                createTime = Long.parseLong(contentMsg.get(2) + "000");//下线时间
                                double fee = contentMsg.getDouble(3);//手续费
                                String users = contentMsg.getString(4);//用户集合
                                //会员抽取金币日志
                                MemberAmountLog memberAmountLog = new MemberAmountLog();
                                memberAmountLog.setGameType(gameType);
                                memberAmountLog.setMultiple(multiple);
                                memberAmountLog.setGameTime(new Date(createTime));
                                memberAmountLog.setAmount(fee);
                                memberAmountLog.setUsers(users);
                                saveMemberAmountLog(memberAmountLog);
                            }else {
                                System.out.println("收到错误消息:消息内容：" + contentMsg + "消息编号：" + msgType+"消息长度："+contentMsg.length());
                                break;
                            }

                            break;
                        case 200:
                            if (contentMsg.length()==2){
                                try {
                                    int plIndex = contentMsg.getInt(0);//平台   0self 1de 2 pt 3mg
                                    JSONArray ms = contentMsg.getJSONArray(1);
                                    Connection con = LogDBConnectO.getCon(1);
                                    try {
                                        StringBuffer sql = new StringBuffer("insert into ");
                                        if(plIndex==3){
                                            sql.append(" log_member_betting_MG ");
                                            sql.append("(`betUID`,`createDateUTC`,`gameStartTimeUTC`,`gameEndTimeUTC`,`playerId`,`productId`, ");
                                            sql.append(" `productPlayerId`,`platform`,`gameCode`,`currency`,`betAmount`,`payoutAmount`, ");
                                            sql.append(" `betStatus`,`PCA`,`externalTransactionId`, `metadata`) ");
                                            sql.append(" values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) ");
                                            PreparedStatement ps =con.prepareStatement(sql.toString(), Statement.RETURN_GENERATED_KEYS);
                                            try {
                                                for (int j = 0; j < ms.length() ; j++) {
                                                    JSONObject m = ms.getJSONObject(j);
                                                    ps.setObject(1,m.getString("betUID"));
                                                    ps.setObject(2,m.getString("createdDateUTC"));
                                                    ps.setObject(3,m.getString("gameStartTimeUTC"));
                                                    ps.setObject(4,m.getString("gameEndTimeUTC"));
                                                    ps.setObject(5,m.getString("playerId"));
                                                    ps.setObject(6,m.getString("productId"));
                                                    ps.setObject(7,m.getString("productPlayerId"));
                                                    ps.setObject(8,m.getString("platform"));
                                                    ps.setObject(9,m.getString("gameCode"));
                                                    ps.setObject(10,m.getString("currency"));
                                                    ps.setObject(11,m.getDouble("betAmount"));
                                                    ps.setObject(12,m.getDouble("payoutAmount"));
                                                    ps.setObject(13,m.getString("betStatus"));
                                                    ps.setObject(14,(!m.isNull("PCA")) ? m.get("PCA") : "");
                                                    ps.setObject(15,m.getString("externalTransactionId"));
                                                    ps.setObject(16,m.getJSONObject("metadata").toString());
                                                    ps.executeUpdate();
                                                }
                                            }catch (Exception e){
                                                e.printStackTrace();
                                            }finally {
                                                ps.close();
                                            }
                                        }else if(plIndex==2){
                                            sql.append(" log_member_betting_PT ");
                                            sql.append(" (`PlayerName`,`ProviderPlayerId`,`WindowCode`,`GameId`,`GameCode`,`GameType`, ");
                                            sql.append(" `GameName`,`SessionId`,`Bet`,`Win`,`ProgressiveBet`,`ProgressiveWin`, ");
                                            sql.append(" `Balance`,`CurrentBet`,`GameDate`, `LiveNetwork`,`ExitGame`,`RNum`) ");
                                            sql.append(" values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) ");
                                            PreparedStatement ps =con.prepareStatement(sql.toString(), Statement.RETURN_GENERATED_KEYS);
                                            try {
                                                for (int j = 0; j < ms.length() ; j++) {
                                                    JSONObject m = ms.getJSONObject(j);
                                                    ps.setObject(1,m.getString("PlayerName"));
                                                    ps.setObject(2,m.getString("ProviderPlayerId"));
                                                    ps.setObject(3,m.getInt("WindowCode"));
                                                    ps.setObject(4,m.getString("GameId"));
                                                    ps.setObject(5,m.getString("GameCode"));
                                                    ps.setObject(6,m.getString("GameType"));
                                                    ps.setObject(7,m.getString("GameName"));
                                                    ps.setObject(8,m.getString("SessionId"));
                                                    ps.setObject(9,m.getDouble("Bet"));
                                                    ps.setObject(10,m.getDouble("Win"));
                                                    ps.setObject(11,m.getDouble("ProgressiveBet"));
                                                    ps.setObject(12,m.getDouble("ProgressiveWin"));
                                                    ps.setObject(13,m.getDouble("Balance"));
                                                    ps.setObject(14,(m.getDouble("CurrentBet")));
                                                    ps.setObject(15,m.getString("GameDate"));
                                                    ps.setObject(16,m.getString("LiveNetwork"));
                                                    ps.setObject(17,m.getString("ExitGame"));
                                                    ps.setObject(18,m.getString("RNum"));
                                                    ps.executeUpdate();
                                                }
                                            }catch (Exception e){
                                                e.printStackTrace();
                                            }finally {
                                                ps.close();
                                            }
                                        }else if (plIndex==1){
                                            sql.append(" log_member_betting_DE ");
                                            sql.append("(`userId`,`fundsChangeOld`,`fundsChangeNew`,`Win`,`GameDate`,`Bet`, ");
                                            sql.append(" `productId`) ");
                                            sql.append(" values(?,?,?,?,?,?,?) ");
                                            PreparedStatement ps =con.prepareStatement(sql.toString(), Statement.RETURN_GENERATED_KEYS);
                                            try {
                                                for (int j = 0; j < ms.length() ; j++) {
                                                    JSONArray m = ms.getJSONArray(j);
                                                    ps.setObject(1,m.getString(0));
                                                    ps.setObject(2,m.getString(1));
                                                    ps.setObject(3,m.getString(2));
                                                    ps.setObject(4,m.getString(3));
                                                    ps.setObject(5,m.getString(4));
                                                    ps.setObject(6,m.getString(5));
                                                    ps.setObject(7,m.getString(6));
                                                    ps.executeUpdate();
                                                }
                                            }catch (Exception e){
                                                e.printStackTrace();
                                            }finally {
                                                ps.close();
                                            }
                                        }
                                        sql=null;
                                    }catch (Exception e){
                                        e.printStackTrace();
                                    } finally {
                                        LogDBConnectO.redCon(1, con);
                                    }
                                }catch (Exception e){
                                    e.printStackTrace();
                                }
                            }else {
                                System.out.println("收到错误消息:消息内容：" + contentMsg + "消息编号：" + msgType+"消息长度："+contentMsg.length());
                                break;
                            }

                            break;
                        default:
                            System.out.println("收到错误消息：" + msg + "没有此类消息类型！！！");

                    }
                }catch (Exception e){
                    Log.errorLog(e.getMessage());
                    Log.errorLog(e.getStackTrace());
                }
            }catch (Exception e){
                System.out.println("收到错误消息:消息主体为空，消息编号："+msgType);
            }
        }catch (Exception e){
            System.out.println("收到错误消息:消息编号为空");
        }
    }

    /**
     * 保存会员提款账户日志
     * @param memberDrawingAccountLog
     * @author
     * @date 2020/8/5 0005 15:19
     * @return void
     */
    private void saveMemberDrawingAccountLog(MemberDrawingAccountLog memberDrawingAccountLog) {
        StringBuffer sql = new StringBuffer("insert into ");
        sql.append(" log_member_drawing_account");
        sql.append("(userId,content,createDate,createTime) ");
        sql.append("values(?,?,?,?)");
        Object[] params = new Object[]{memberDrawingAccountLog.getUserId(),memberDrawingAccountLog.getContent(),memberDrawingAccountLog.getCreateDate(),memberDrawingAccountLog.getCreateTime()};
        saveOrUpdateBySqlLog(sql.toString(), params);
    }

    /**
     * 保存会员查询交易流水日志
     * @param info
     * @author 
     * @date 2020/7/29 0029 13:59 
     * @return void
     */
    private void saveMemberShowTradeFlowLog(MemberShowTradeFlowLog info) {
        StringBuffer sql = new StringBuffer("insert into ");
        sql.append("log_member_show_trade_flow");
        sql.append("(userId,operationStatus,createDate,createTime) ");
        sql.append("values(?,?,?,?)");
        Object[] params = new Object[]{info.getUserId(),info.getOperationStatus(),info.getCreateDate(),info.getCreateTime()};
        saveOrUpdateBySqlLog(sql.toString(), params);
    }

    /**
     * 保存会员充值日志
     * @param memberRechargeLog
     * @author
     * @date 2020/7/28 0028 11:43 
     * @return void
     */
    private void saveMemberRechargeLog(MemberRechargeLog memberRechargeLog) {
        StringBuffer sql = new StringBuffer("insert into ");
        sql.append("log_member_recharge");
        sql.append("(userId,orderNo,value,createDate,createTime,reIp) ");
        sql.append("values(?,?,?,?,?,?)");
        Object[] params = new Object[]{memberRechargeLog.getUserId(),memberRechargeLog.getOrderNo(),memberRechargeLog.getValue(),memberRechargeLog.getCreateDate(),memberRechargeLog.getCreateTime(),memberRechargeLog.getIp()};
        saveOrUpdateBySqlLog(sql.toString(), params);
    }

    /**
     * 保存会员提现日志
     * @param memberWithdrawalLog
     * @author 
     * @date 2020/7/28 0028 11:43 
     * @return void
     */
    private void saveMemberWithdrawalLog(MemberWithdrawalLog memberWithdrawalLog) {
        StringBuffer sql = new StringBuffer("insert into ");
        sql.append("log_member_withdrawal");
        sql.append("(userId,orderNo,value,createDate,createTime,wiIp) ");
        sql.append("values(?,?,?,?,?,?)");
        Object[] params = new Object[]{memberWithdrawalLog.getUserId(),memberWithdrawalLog.getOrderNo(),memberWithdrawalLog.getValue(),memberWithdrawalLog.getCreateDate(),memberWithdrawalLog.getCreateTime(),memberWithdrawalLog.getIp()};
        saveOrUpdateBySqlLog(sql.toString(), params);
    }

    /**
     * 保存会员信息日志
     * @param entity
     */
    public void saveMemberInfoLog(MemberInfoLog entity){
        StringBuffer sql = new StringBuffer("insert into ");
        sql.append("log_member_info");
        sql.append("(userid,onlineTime,offlineTime,ip) ");
        sql.append("values(?,?,?,?)");
        Object[] params = new Object[]{entity.getUserId(),entity.getOnlineTime(),entity.getOfflineTime(),entity.getIp()};
        saveOrUpdateBySqlLog(sql.toString(), params);
        LogicGameToPlatformServerWorker.memberInfoCount = LogicGameToPlatformServerWorker.memberInfoCount+1;//叠加日志条数
    }

    /**
     * 保存新增会员日志
     * @param entity
     */
    public void saveMemberRegisterLog(MemberRegisterLog entity){
        StringBuffer sql = new StringBuffer("insert into ");
        sql.append("log_member_register");
        sql.append("(userId,userName,createTime,ip,balance,userType,businessId,AppId,nickName,fundsTypeId) ");
        sql.append("values(?,?,?,?,?,?,?,?,?,?)");
        Object[] params = new Object[]{entity.getUserId(),entity.getUserName(),entity.getCreateTime(),entity.getIp(),entity.getBalance(),
                entity.getUserType(),entity.getBusinessId(),entity.getAppId(),entity.getNickName(),entity.getFundsType()};
        try {
            saveOrUpdateBySqlLog(sql.toString(),params);
        }catch (Exception c){
            System.out.println(c);
        }
    }

    /**
     * 保存服务器日志
     * @param entity
     */
    public void saveServerLog(ServerLog entity){
        StringBuffer sql = new StringBuffer("insert into ");
        sql.append("log_server");
        sql.append("(serverNo,logTime,number,userIds) ");
        sql.append("values(?,?,?,?)");
        Object[] params = new Object[]{entity.getServerNo(),entity.getLogTime(),entity.getNumber(),entity.getUserIds()};
        saveOrUpdateBySqlLog(sql.toString(),params);
        LogicGameToPlatformServerWorker.serverCount = LogicGameToPlatformServerWorker.serverCount+1;//叠加日志条数
    }

    /**
     * 保存会员上线日志
     * @param entity
     */
    public void saveMemberOnlineLog(MemberOnlineLog entity){
        try {
            StringBuffer sql = new StringBuffer("SELECT count(t.userId) num  FROM log_member_online t WHERE t.userId  = ?");
            Object[] params = new Object[]{entity.getUserId()};
            List<Map<String,String>> onLineList = queryBySqlLog(sql.toString(),params);
            sql = new StringBuffer("SELECT count(t.userId) num FROM log_member_offline t WHERE t.userId  = ?");
            List<Map<String,String>> offLineList = queryBySqlLog(sql.toString(),params);
            if("0".equals(onLineList.get(0).get("num")) || offLineList.get(0).get("num").equals(onLineList.get(0).get("num"))){
                sql = new StringBuffer("insert into ");
                sql.append("log_member_online");
                sql.append("(userId,serverNo,onLineTime,relation,onlineIp,nickName) ");
                sql.append("values(?,?,?,?,?,?)");
                params = new Object[]{entity.getUserId(),entity.getServerNo(),entity.getOnLineTime(),entity.getKey(),entity.getOnLineIp(),entity.getNickName()};
                saveOrUpdateBySqlLog(sql.toString(),params);
                LogicGameToPlatformServerWorker.memberOnlineCount = LogicGameToPlatformServerWorker.memberOnlineCount+1;//叠加日志条数
            }else {
                sql = new StringBuffer("UPDATE log_member_online t set t.relation = ? WHERE t.userId = ?");
                params = new Object[]{entity.getKey(),entity.getUserId()};
                saveOrUpdateBySqlLog(sql.toString(),params);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    /**
     * 保存会员下线日志
     * @param entity
     */
    public void saveMemberOfflineLog(MemberOfflineLog entity){
        StringBuffer sql = new StringBuffer("insert into ");
        sql.append("log_member_offline");
        sql.append("(userId,serverNo,offLineTime,relation,offLineIp,balance) ");
        sql.append("values(?,?,?,?,?,?)");
        Object[] params = new Object[]{entity.getUserId(),entity.getServerNo(),entity.getOffLineTime(),entity.getKey(),entity.getOffLineIp(),entity.getBalance()};
        saveOrUpdateBySqlLog(sql.toString(),params);
        LogicGameToPlatformServerWorker.memberOfflineCount = LogicGameToPlatformServerWorker.memberOfflineCount+1;//叠加日志条数
    }

    /**
     * 保存会员进入游戏日志
     * @param entity
     */
    public void saveMemberEnterGameLog(MemberEnterGameLog entity){
        StringBuffer sql = new StringBuffer("insert into ");
        sql.append("log_member_enter_game");
        sql.append("(userId,serverNo,enterGameTime,gameType,multiple,relation,enterGameIp) ");
        sql.append("values(?,?,?,?,?,?,?)");
        Object[] params = new Object[]{entity.getUserId(),entity.getServerNo(),entity.getEnterGameTime(),
                entity.getGameType(),entity.getMultiple(),entity.getKey(),
                entity.getEnterGameIp()};
        saveOrUpdateBySqlLog(sql.toString(),params);
        LogicGameToPlatformServerWorker.memberEnterGameCount = LogicGameToPlatformServerWorker.memberEnterGameCount+1;//叠加日志条数
    }

    /**
     * 保存会员退出游戏日志
     * @param entity
     */
    public void saveMemberQuitGameLog(MemberQuitGameLog entity){
        StringBuffer sql = new StringBuffer("insert into ");
        sql.append("log_member_quit_game");
        sql.append("(userId,serverNo,quitGameTime,relation,gameType,multiple,balanceChange,quitGameIp) ");
        sql.append("values(?,?,?,?,?,?,?,?)");
        Object[] params = new Object[]{entity.getUserId(),entity.getServerNo(),entity.getQuitGameTime(),entity.getKey(),
                entity.getGameType(),entity.getMultiple(),entity.getBalanceChange(),entity.getQuitGameIp()};
        saveOrUpdateBySqlLog(sql.toString(),params);
        LogicGameToPlatformServerWorker.memberQuitGameCount = LogicGameToPlatformServerWorker.memberQuitGameCount+1;//叠加日志条数
    }

    /**
     * 保存会员的资金流水日志
     * @param memberFundFlowLog
     */
    public void saveMemberFundFlowLog(MemberFundFlowLog memberFundFlowLog){
        StringBuffer sql = new StringBuffer("insert into ");
        sql.append("log_member_fund_flow");
        sql.append("(userId,gameTime,gameType,multiple,balanceChange,orderId) ");
        sql.append("values(?,?,?,?,?,?)");
        Object[] params = new Object[]{memberFundFlowLog.getUserId(),memberFundFlowLog.getGameTime(),memberFundFlowLog.getGameType(),
                memberFundFlowLog.getMultiple(),memberFundFlowLog.getBalanceChange(),memberFundFlowLog.getOrderId()};
        saveOrUpdateBySqlLog(sql.toString(),params);
        LogicGameToPlatformServerWorker.memberFundFlowCount = LogicGameToPlatformServerWorker.memberFundFlowCount+1;//叠加日志条数
    }

    /**
     * 保存会员的手续费流水日志
     * @param memberAmountLog
     */
    public void saveMemberAmountLog(MemberAmountLog memberAmountLog){
        StringBuffer sql = new StringBuffer("insert into ");
        sql.append("log_member_fee");
        sql.append("(amount,gameTime,gameType,multiple,users) ");
        sql.append("values(?,?,?,?,?)");
        Object[] params = new Object[]{memberAmountLog.getAmount(),memberAmountLog.getGameTime(),memberAmountLog.getGameType(),
                memberAmountLog.getMultiple(),memberAmountLog.getUsers()};
        saveOrUpdateBySqlLog(sql.toString(),params);
        LogicGameToPlatformServerWorker.memberFeeCount = LogicGameToPlatformServerWorker.memberFeeCount+1;//叠加日志条数
    }

    /**
     * 保存会员提款账户
     * @param memberBankAccount
     * @author
     * @date 2020/8/5 0005 15:38
     * @return void
     */
    private void saveMemberBankAccount(MemberBankAccount memberBankAccount) {
        StringBuffer sql = new StringBuffer("select count(t.id) num from member_bank_account t WHERE t.game_account = ? and t.drawing_type = ?");
        Object[] params = new Object[]{memberBankAccount.getGameAccount(),memberBankAccount.getDrawingType()};
        List<Map<String,String>> onLineList = queryBySql(sql.toString(),params);
        if("0".equals(onLineList.get(0).get("num"))){
            sql = new StringBuffer("insert into ");
            sql.append("member_bank_account");
            sql.append("(game_account,drawing_type,bank_account,bank_account_name) ");
            sql.append("values(?,?,?,?)");
            params = new Object[]{memberBankAccount.getGameAccount(),memberBankAccount.getDrawingType(),memberBankAccount.getBankAccount(),memberBankAccount.getBankAccountName()};
            saveOrUpdateBySql(sql.toString(),params);
        }else {
            sql = new StringBuffer("update member_bank_account t set t.bank_account = ?,t.bank_account_name = ? WHERE t.game_account = ? and t.drawing_type = ?");
            params = new Object[]{memberBankAccount.getBankAccount(),memberBankAccount.getBankAccountName(),memberBankAccount.getGameAccount(),memberBankAccount.getDrawingType()};
            saveOrUpdateBySql(sql.toString(),params);
        }
    }

    /**
     * 保存/修改会员上线
     * @param entity
     */
    public void saveAndUpdateMemberOnLine(MemberOnlineLog entity){
        StringBuffer sql = new StringBuffer("select count(t.userId) num from member_online t WHERE t.userId = ? ");
        Object[] params = new Object[]{entity.getUserId()};
        List<Map<String,String>> onLineList = queryBySql(sql.toString(),params);
        if("0".equals(onLineList.get(0).get("num"))){
            sql = new StringBuffer("insert into ");
            sql.append("member_online");
            sql.append("(userId,relation,ip) ");
            sql.append("values(?,?,?)");
            params = new Object[]{entity.getUserId(),entity.getKey(),entity.getOnLineIp()};
            saveOrUpdateBySql(sql.toString(),params);
        }else {
            sql = new StringBuffer("update member_online t set t.relation = ?,t.ip = ? WHERE t.userId = ? ");
            params = new Object[]{entity.getKey(),entity.getUserId(),entity.getOnLineIp()};
            saveOrUpdateBySql(sql.toString(),params);
        }
    }

    /**
     * 保存会员上线
     * @param entity
     */
    public void saveMemberOnline(MemberOnLine entity){
        StringBuffer sql = new StringBuffer("delete from member_online");
        Object[] params = new Object[]{};
        saveOrUpdateBySql(sql.toString(),params);
        sql = new StringBuffer("insert into ");
        sql.append("member_online");
        sql.append("(userId,ip) ");
        sql.append("values(?,?)");
        params = new Object[]{entity.getUserId(),entity.getOnLineIp()};
        saveOrUpdateBySql(sql.toString(),params);
    }

    /**
     * 删除会员上线
     * @param entity
     */
    public void deleteMemberOnline(MemberOfflineLog entity){
        StringBuffer sql = new StringBuffer("delete from ");
        sql.append("member_online t ");
        sql.append("where t.userId = ? ");
        Object[] params = new Object[]{entity.getUserId()};
        saveOrUpdateBySql(sql.toString(),params);
    }

    /**
     * 清空在线会员
     * @author lijie1
     * @date 2020/9/9 0009 9:40
     * @return void
     */
    public void deleteMemberOnlineAll(){
        StringBuffer sql = new StringBuffer("delete from ");
        sql.append("member_online t ");
        sql.append("where 1=1 ");
        Object[] params = new Object[]{};
        saveOrUpdateBySql(sql.toString(),params);
    }

    /**
     * 保存会员游戏
     * @param entity
     */
    public void saveMemberGame(MemberEnterGameLog entity){
        StringBuffer sql = new StringBuffer("insert into ");
        sql.append("member_game ");
        sql.append("(userId,relation,gameType,multiple) ");
        sql.append("values(?,?,?,?) ");
        Object[] params = new Object[]{entity.getUserId(),entity.getKey(),entity.getGameType(),entity.getMultiple()};
        saveOrUpdateBySql(sql.toString(),params);
    }

    /**
     * 删除会员游戏
     * @param entity
     */
    public void deleteMemberGame(MemberQuitGameLog entity){
        StringBuffer sql = new StringBuffer("delete from ");
        sql.append("member_game t " ).append("where t.userId = ? ");
        Object[] params = new Object[]{entity.getUserId()};
        saveOrUpdateBySql(sql.toString(),params);
    }

    /**
     * 新增会员
     * @param memberInfo
     */
    public void saveMemberInfo(MemberInfo memberInfo){
        try {
            StringBuffer sql = new StringBuffer("insert into ");
            sql.append("member_play_account");
            sql.append("(account,account_type,slice_value,slice_name,grade_value,grade_name,cur_amount,area_id,area_name,register_time,register_channel,accountName,phone_number,nick_name,foundTypeId) ");
            sql.append("values(?,?,");
            sql.append(" (select t.id from member_member_slice t where 1=1 order by t.count LIMIT 1), ");
            sql.append(" (select t.slice_name from member_member_slice t where 1=1 order by t.count LIMIT 1), ");
            sql.append(" (select t.id from member_member_grade t where 1=1 order by t.up_lv_exp LIMIT 1), ");
            sql.append(" (select t.member_grade_name from member_member_grade t where 1=1 order by t.up_lv_exp LIMIT 1), ");
            sql.append(" ?,?,?,?,?,?,?,?,?) ");
            Object[] params = new Object[]{memberInfo.getAccount(),memberInfo.getAccount_type(),
                    memberInfo.getCur_amount(),
                    memberInfo.getArea_id(),memberInfo.getArea_name(),
                    memberInfo.getRegister_time(),memberInfo.getRegister_channel(),memberInfo.getAccountName(),memberInfo.getPhoneNumber(),
                    memberInfo.getNickName(),memberInfo.getFoundTypeId()};
            saveOrUpdateBySql(sql.toString(),params);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    /**
     * 修改会员的基本信息（冻结资金，余额）
     * @param memberInfo
     */
    public void updateMemberInfo(MemberInfo memberInfo,boolean f){
        StringBuffer sql = new StringBuffer("UPDATE ");
        sql.append(" member_play_account t ");
        sql.append(" SET ");
        sql.append(" t.frozen_amount = frozen_amount + ? , ");
        if (f){
            sql.append(" t.cur_amount = cur_amount + ? ");
        }else {
            sql.append(" t.cur_amount = ? ");
        }
        sql.append(" WHERE ");
        sql.append(" t.accountName = ? ");
        Object[] params = new Object[]{memberInfo.getFrozen_amount(),memberInfo.getCur_amount(),memberInfo.getAccount()};
        saveOrUpdateBySql(sql.toString(),params);
    }

    /**
     * 修改会员的基本信息（有效投注，有效投注和）
     * @param memberInfo
     */
    public void updateMemberInfoByEffectBet(MemberInfo memberInfo){
        StringBuffer sql = new StringBuffer("UPDATE ");
        sql.append(" member_play_account t ");
        sql.append(" SET ");
        sql.append(" t.effect_bet = effect_bet + ? , ");
        sql.append(" t.effect_betbalance = effect_betbalance + ? ");
        sql.append(" WHERE ");
        sql.append(" t.accountName = ? ");
        Object[] params = new Object[]{memberInfo.getEffectBet(),memberInfo.getEffectBetBalance(),memberInfo.getAccountName()};
        saveOrUpdateBySql(sql.toString(),params);
    }

    /**
     * 修改会员的基本信息（昵称）
     * @param memberInfo
     */
    private void updateMemberInfoByNickName(MemberInfo memberInfo) {
        StringBuffer sql = new StringBuffer("UPDATE ");
        sql.append(" member_play_account t ");
        sql.append(" SET ");
        sql.append(" t.nick_name = ? ");
        sql.append(" WHERE ");
        sql.append(" t.accountName = ? ");
        Object[] params = new Object[]{memberInfo.getNickName(),memberInfo.getAccountName()};
        saveOrUpdateBySql(sql.toString(),params);
    }

    /**
     * 修改会员的基本信息（登录时间）
     * @param memberInfo
     */
    public void updateMemberInfoByRegisterTime(MemberInfo memberInfo,boolean fal){
        StringBuffer sql = new StringBuffer("UPDATE ");
        sql.append(" member_play_account t ");
        sql.append(" SET ");
        sql.append(" t.login_time = ? ");
        if (!fal){
            sql.append(", t.login_time = 'null' ");
        }
        sql.append(" WHERE ");
        sql.append(" t.accountName = ? ");
        Object[] params = new Object[]{memberInfo.getRegister_time(),memberInfo.getAccountName()};
        saveOrUpdateBySql(sql.toString(),params);
    }

    /**
     *  保存用户交易流水和
     * @param memberFundsFlow
     * @author
     * @date 2020/9/15 0015 9:43
     * @return void
     */
    public void saveMemberFundsFlow(MemberFundsFlow memberFundsFlow){
        StringBuffer selectSql = new StringBuffer("select count(1) num  from member_trade_flow t where t.userId = ?");
        Object[] params = new Object[]{memberFundsFlow.getUserId()};
        List<Map<String,String>> list = queryBySql(selectSql.toString(),params);
        int i = 0;
        if(list.size()>0){
            i = Integer.parseInt(list.get(0).get("num"));
        }
        if (i>0){
            StringBuffer sql = new StringBuffer("UPDATE ");
            sql.append(" member_trade_flow t ");
            sql.append(" SET ");
            sql.append(" t.fundsflow = fundsflow + ? ");
            sql.append(" WHERE ");
            sql.append(" t.userId = ? ");
            params = new Object[]{memberFundsFlow.getFundsflow(),memberFundsFlow.getUserId()};
            saveOrUpdateBySql(sql.toString(),params);
        }else {
            StringBuffer insertSql = new StringBuffer("insert into ");
            insertSql.append("member_trade_flow");
            insertSql.append("(userId,fundsflow) ");
            insertSql.append("values(?,?)");
            params = new Object[]{memberFundsFlow.getUserId(),memberFundsFlow.getFundsflow()};
            saveOrUpdateBySql(insertSql.toString(),params);
        }
    }

    /**
     * 修改会员的基本信息
     * @param memberInfo
     */
    public void updateMemberInfoByLoginTime(MemberInfo memberInfo){
        StringBuffer sql = new StringBuffer("UPDATE ");
        sql.append(" member_play_account t ");
        sql.append(" SET ");
        sql.append(" t.login_time = ? ");
        sql.append(" WHERE ");
        sql.append(" t.accountName = ? ");
        Object[] params = new Object[]{memberInfo.getLoginTime(),memberInfo.getAccount()};
        saveOrUpdateBySql(sql.toString(),params);
    }

    /**
     * 查询会员信息count
     * @param memberInfo
     * @return
     */
    public int queryMemberInfoCount(MemberInfo memberInfo){
        StringBuffer sql = new StringBuffer(" SELECT count( t.id ) num ");
        sql.append(" FROM member_play_account t ");
        sql.append(" WHERE ");
        sql.append(" t.account = ?  ");
        sql.append(" AND t.accountName = ? ");
        Object[] params = new Object[]{memberInfo.getAccount(),memberInfo.getAccountName()};
        List<Map<String,String>> list = queryBySql(sql.toString(),params);
        int i = 0;
        if(list.size()>0){
            i = Integer.parseInt(list.get(0).get("num"));
        }
        return i;
    }

    /**
     * 查询会员游戏信息
     * @param memberEnterGameLog
     * @return
     */
    public int queryMemberGameInfo(MemberEnterGameLog memberEnterGameLog){
        StringBuffer sql = new StringBuffer(" SELECT count( userId ) num ");
        sql.append(" FROM member_game t ");
        sql.append(" WHERE ");
        sql.append(" t.userId = ?  ");
        Object[] params = new Object[]{memberEnterGameLog.getUserId()};
        List<Map<String,String>> list = queryBySql(sql.toString(),params);
        int i = 0;
        if(list.size()>0){
            i = Integer.parseInt(list.get(0).get("num"));
        }
        return i;
    }

    /**
     * 查询会员信息
     * @param accountName
     * @return
     */
    public List<Map<String,String>> queryMemberInfo(String accountName){
        StringBuffer sql = new StringBuffer(" SELECT t.account account ");
        sql.append(" FROM member_play_account t ");
        sql.append(" WHERE ");
        sql.append(" t.accountName = ? ");
        Object[] params = new Object[]{accountName};
        List<Map<String,String>> list = queryBySql(sql.toString(),params);
        return list;
    }

    /**
     * 保存ip审查
     * @param memberIpCheck
     */
    public void saveMemberIpCheck(MemberIpCheck memberIpCheck){
        StringBuffer sql = new StringBuffer("insert into ");
        sql.append("member_ip_check");
        sql.append("(account_no,use_time,use_ip,use_type,ip_use_count) ");
        sql.append("values(?,?,?,?,?)");
        Object[] params = new Object[]{memberIpCheck.getAccountNo(),memberIpCheck.getUseTime(),
                memberIpCheck.getUseIp(),memberIpCheck.getUseType(),
                memberIpCheck.getIpUseCount()};
        saveOrUpdateBySql(sql.toString(),params);

    }

    /**
     * 修改ip审查
     * @param memberIpCheck
     */
    public void updateMemberIpCheck(MemberIpCheck memberIpCheck){
        StringBuffer sql = new StringBuffer(" UPDATE ");
        sql.append(" member_ip_check t ");
        sql.append(" SET ");
        sql.append(" t.use_time = ?, t.ip_use_count = ip_use_count + ? ");
        sql.append(" WHERE ");
        sql.append(" t.account_no = ? and t.use_ip = ?");
        Object[] params = new Object[]{memberIpCheck.getUseTime(),memberIpCheck.getIpUseCount(),memberIpCheck.getAccountNo(),memberIpCheck.getUseIp()};
        saveOrUpdateBySql(sql.toString(),params);
    }

    /**
     * 查询当前会员是否用过次ip
     * @param memberIpCheck
     */
    public List<Map<String, String>> queryMemberIpCheck(MemberIpCheck memberIpCheck){
        StringBuffer sql = new StringBuffer(" select * from member_ip_check ");
        sql.append(" where ");
        sql.append(" account_no = ? ");
        sql.append(" and use_ip = ? ");
        sql.append(" and use_type = 1 ");
        Object[] params = new Object[]{memberIpCheck.getAccountNo(),memberIpCheck.getUseIp()};
        return queryBySql(sql.toString(),params);
    }

    /**
     * 保存会员的行为
     * @param memberBehavior
     */
    public void saveMemberBehavior(MemberBehavior memberBehavior){
        StringBuffer sql = new StringBuffer("insert into ");
        sql.append("member_behavior");
        sql.append("(game_account,ip_address,oper_time,behavior_content,behavior_type) ");
        sql.append("values(?,?,?,?,?)");
        Object[] params = new Object[]{memberBehavior.getGameAccount(),memberBehavior.getIpAddress(),memberBehavior.getOperTime(),
                memberBehavior.getBehaviorContent(),memberBehavior.getBehaviorType()};
        saveOrUpdateBySql(sql.toString(),params);
    }

    /**
     * 保存用户流水
     * @param memberRunWater
     */
    public void saveMemberRunWater(MemberRunWater memberRunWater){
        StringBuffer sql = new StringBuffer("insert into ");
        sql.append("member_run_water");
        sql.append("(game_account,betting_time,game_type,game_name,bet_amount,bet_result) ");
        sql.append("values(?,?,?,?,?,?)");
        Object[] params = new Object[]{memberRunWater.getGameAccount(),memberRunWater.getBettingTime(),memberRunWater.getGameType(),
                memberRunWater.getGameName(),memberRunWater.getBetAmount(),memberRunWater.getBetResult()};
        saveOrUpdateBySql(sql.toString(),params);
    }

     /**
     * 通过sql进行数据存储（日志数据库）
     * @param sql
     * @param params
     */
    public void saveOrUpdateBySqlLog(String sql,Object[] params){
        try {
            Connection ss = LogDBConnectO.getCon(1);//获取数据库连接
            try {
                PreparedStatement ps = ss.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
                for (int i = 0; i < params.length; i++) {
                    ps.setObject(i + 1, params[i]);
                }
                ps.executeUpdate();
                ResultSet rs = ps.getGeneratedKeys();
                while (rs.next()) {
                    int id = rs.getInt(1);
                    //System.out.println("*******************************" + id);
                }
                rs.close();
                ps.close();
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                LogDBConnectO.redCon(1, ss);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    /**
     * 通过sql进行数据存储
     * @param sql
     * @param params
     */
    public void saveOrUpdateBySql(String sql,Object[] params){
        try {
            Connection ss = DBConnectO.getCon(1);//获取数据库连接
            try {
                PreparedStatement ps = ss.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
                for (int i = 0; i < params.length; i++) {
                    ps.setObject(i + 1, params[i]);
                }
                ps.executeUpdate();
                ResultSet rs = ps.getGeneratedKeys();
                while (rs.next()) {
                    int id = rs.getInt(1);
//                    System.out.println("*******************************" + id);
                }
                rs.close();
                ps.close();
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                DBConnectO.redCon(1, ss);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    /**
     * 通过sql进行数据查询（日志数据库）
     * @param sql
     * @param params
     */
    public List<Map<String, String>> queryBySqlLog(String sql,Object[] params){
        try {
            Connection ss = LogDBConnectO.getCon(1);//获取数据库连接
            Map<String, String> dataMap = new HashMap<String, String>();
            List<Map<String, String>> dataList = new ArrayList<Map<String, String>>();
            try {
                PreparedStatement ps = ss.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
                for (int i = 0; i < params.length; i++) {
                    ps.setObject(i + 1, params[i]);
                }
                //System.out.println("sql:"+ps.toString());
                ResultSet rs = ps.executeQuery();
                ResultSetMetaData resultData = rs.getMetaData();
                int count = resultData.getColumnCount();
                while (rs.next()) {
                    for (int i = 1; i <= count; i++) {
                        String key = resultData.getColumnLabel(i);
                        String value = rs.getString(i);
                        dataMap.put(key, value);
                    }
                    dataList.add(dataMap);
                }
                rs.close();
                ps.close();
                return dataList;
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                LogDBConnectO.redCon(1, ss);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 通过sql进行数据查询
     * @param sql
     * @param params
     */
    public List<Map<String, String>> queryBySql(String sql,Object[] params){
        try {
            Connection ss = DBConnectO.getCon(1);//获取数据库连接
            Map<String, String> dataMap = new HashMap<String, String>();
            List<Map<String, String>> dataList = new ArrayList<Map<String, String>>();
            try {
                PreparedStatement ps = ss.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
                for (int i = 0; i < params.length; i++) {
                    ps.setObject(i + 1, params[i]);
                }
                //System.out.println("sql:"+ps.toString());
                ResultSet rs = ps.executeQuery();
                ResultSetMetaData resultData = rs.getMetaData();
                int count = resultData.getColumnCount();
                while (rs.next()) {
                    for (int i = 1; i <= count; i++) {
                        String key = resultData.getColumnLabel(i);
                        String value = rs.getString(i);
                        dataMap.put(key, value);
                    }
                    dataList.add(dataMap);
                }
                rs.close();
                ps.close();
                return dataList;
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                DBConnectO.redCon(1, ss);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

}
